/* thisFile By XiaoKang Create at 2008-11-21 from net*/
var k=0;
function _G(fctId){
	return document.getElementById(fctId);
}
//取得某对象，若提供ID下的对象不存在则自动创建
function c_G(fctId,fctClassName){
	var varTempDivObj=_G(fctId);
	if(!varTempDivObj){
		GetPyzyIframe("ifm"+fctId);
		varTempDivObj=document.createElement("div");
		varTempDivObj.id=fctId;
		if(fctClassName && fctClassName!="")varTempDivObj.className=fctClassName;
		document.body.appendChild(varTempDivObj);
	}
	return varTempDivObj;
}

//取得某ID的iframe对象，若不存在该ID的对象则自动创建
function GetPyzyIframe(fctIfmId,fctVisibility,fctTop,fctLeft,fctWidth,fctHeight){
	var varTempIfmObj=_G(fctIfmId);
	if(!varTempIfmObj){
		varTempIfmObj=document.createElement("iframe");
		varTempIfmObj.id=fctIfmId;
		varTempIfmObj.style.position="absolute";
		varTempIfmObj.style.zIndex="1";
		varTempIfmObj.style.visibility="hidden";
		varTempIfmObj.style.border="solid 0px #000000";
		varTempIfmObj.frameBorder="0";
		document.body.appendChild(varTempIfmObj);
	}
	if(fctTop)varTempIfmObj.style.top=fctTop+"px";
	if(fctLeft)varTempIfmObj.style.left=fctLeft+"px";
	if(fctWidth)varTempIfmObj.style.width=fctWidth+"px";
	if(fctHeight)varTempIfmObj.style.height=fctHeight+"px";
	if(fctVisibility)varTempIfmObj.style.visibility=(document.all?fctVisibility:"hidden ");
	return varTempIfmObj;
}
//取得某对象的坐标位置、宽、高
function getPosition(obj){
	var top=0;
	var left=0;
	var width=obj.offsetWidth;
	var height=obj.offsetHeight;
	while(obj.offsetParent){
		top+=obj.offsetTop;
		left+=obj.offsetLeft;
		obj=obj.offsetParent;
	}
	return{"top":top,"left":left,"width":width,"height":height};
}
//取得编码存储框对象
function GetValueToInputObj(fctThisObj){
	if(!fctThisObj)return null;
	var varThisObjAutoInput=(fctThisObj.getAttributeNode("value_to_input")?fctThisObj.getAttributeNode("value_to_input").value:"");
	if(varThisObjAutoInput=="")return null;
	return _G(varThisObjAutoInput);
}
//自动触发下一个对象的Act事件
function AutoNextInputAct(fctThisObj,fctAct){
	var varNextInput=fctThisObj.getAttributeNode("nextinput");
	if(varNextInput && varNextInput!=""){
		if(document.all){
			eval("_G('"+varNextInput.value+"')."+fctAct+"()");
		}else{
			var evt = document.createEvent("MouseEvents");
			evt.initEvent(fctAct,true,true);
			_G(varNextInput.value).dispatchEvent(evt);
		}
		_G(varNextInput.value).focus();
	}
}
//给某对象的某事件增加处理函数AddFunToObj(document,"onclick","alert('1');")
function AddFunToObj(fctObj,fctAct,fctFunction){
	if(fctObj.addEventListener){ //!IE
		fctObj.addEventListener(fctAct.replace("on",""),function(e){
			e.cancelBubble=!eval(fctFunction);
		},false);
	}else if(fctObj.attachEvent){ //IE
		fctObj.attachEvent(fctAct,function(){
			return eval(fctFunction);
	});
	}
}

//隐藏列表
function _Hidden(e){
	e=e?e:event;
	var varMenuObj=c_G("divAddressMenu");
	var varThisObj=varMenuObj.obj;
	if(varMenuObj.style.visibility!="hidden"){
		if(e){
			var EventOBJ=(e.srcElement?e.srcElement:e.target);
			if(EventOBJ.id=="menuPageS" && EventOBJ.style.color==""){ //如果点的是“上一页”则向上翻页
				varPageId=varPageId-1;
				GetCityList(EventOBJ);
			}
			if(EventOBJ.id=="menuPageE" && EventOBJ.style.color==""){ //如果点的是“下一页”则向下翻页
				varPageId=varPageId+1;
				GetCityList(EventOBJ);
			}
			if(varThisObj==EventOBJ || EventOBJ.id.indexOf("menuPage")==0 || EventOBJ.id.indexOf("divAddressMenu")==0) return false;
		}
		var varThisObjAutoInput=GetValueToInputObj(varThisObj); //取得城市编码值存储对象
		if(_G("menuA1")){ //如果下拉菜单中存在第一个城市
			if(!varThisObjAutoInput)varThisObjAutoInput=varThisObj;
			if(varThisObjAutoInput.value=="" || varThisObjAutoInput==varThisObj){ //编码框中无值
				//WriteCity("1");
			}
		}else if(EventOBJ.id.indexOf("menuA")<0){ //如果下拉菜单中不存在满足条件的城市
			if(varThisObj)varThisObj.value="";
		}
		varMenuObj.style.visibility="hidden";
		GetPyzyIframe("ifm"+varMenuObj.id,"hidden");
		
	}
}

/**********日历选择功能 End  2008-11-21*************/
//输出日历样式表 2008-11-21
//width:157px !important;width:162px;height:178px !important;height:186px;
document.write('\<style type="text/css">\
		.DateListBox{float:left;border:solid #0080B7 1px;font-size:12px;text-align:center;width:148px;_width:155px; height:168px; _height:168px; line-height:16px;}\
		.DateListBox h1{width:100%;background:#0080B7;color:#fff;font-size:12px;height:20px;font-weight:bold;line-height:20px;vertical-align:middle;margin:0px;}\
		.DateListBox h1 span {cursor:pointer;}\
		.DateListBox div{float:left; border:solid #9ab4d1 1px; border-left:0px; border-right:0px; background:#f5f8ff;color:#000; width:21px !important;width:22px;height:20px;font-size:12px;line-height:20px;vertical-align:middle;}\
		.DateListBox a{float:left;color:#000;border:solid #ffffff 1px;background-color:#ffffff;width:19px !important;width:20px;height:18px;font-size:12px;line-height:18px;vertical-align:middle;text-decoration: none;}\
		.DateListBox a:hover{background-color:#FF6600; color:#fff;}\
		.DateListBox a.Select{cursor:pointer;border:solid #DEB4B4 1px;background:#FAE0CF;color:#FF0000;}\
		.PyzyDateBox{position:absolute;z-index:1;visibility:hidden;background:#FFFFFF;height:168px;_height:170px;width:300px;_width:314px;}\
	</style>\
');
//取得日历列表，该函数输出的内容需要根据需求放置到特定的容器中，如浮动层、固定DIV…
function GetMonthHTML(fctStaDate,fctDate,xk,fctJNum){
	//alert(fctStaDate+'|'+fctDate+xk)
	
	//_G('ttt').innerHTML+=k%2;
	if(!fctDate)fctDate=new Date(); //默认为当前日期
	var varYear=fctDate.getFullYear();
	var varMonth=fctDate.getMonth();
	var varNextMonth=new Date(varYear,varMonth+1,1);
	
	var varThisMonthButDay = new Date(varNextMonth-86400000); //本月最后一天
	var varThisDate,varThisWeekDay,varThisMonthHTML="";
	var xkHtml=k%2==0 ? '&nbsp;&nbsp; >' : '< &nbsp;&nbsp;';
	varThisMonthHTML+=k%2==0 ? '<h1><span title="上一月" onclick="ShowTwoMonthList(null,'+(fctJNum-1)+',\'thisDay\')">< &nbsp;&nbsp;'+varYear+'年'+(varMonth+1)+'月</span></h1>':'<h1><span title="下一月" onclick="ShowTwoMonthList(null,'+(fctJNum+1)+',\'thisDay\')">'+varYear+'年'+(varMonth+1)+'月&nbsp;&nbsp; ></span></h1>';
	k++;
	varThisMonthHTML+="<div>日</div><div>一</div><div>二</div><div>三</div><div>四</div><div>五</div><div>六</div>"
	for(var DayI=1;DayI<=varThisMonthButDay.getDate();DayI++){
		varThisDate=new Date(varYear,varMonth,DayI);
		varThisWeekDay=varThisDate.getDay();
		if(DayI==1){
			for(var spcI=0;spcI<varThisWeekDay;spcI++){
				varThisMonthHTML+="<a></a>"
			}
		}
	varThisMonthHTML+="<a "+((fctStaDate && fctStaDate!="")?(varThisDate<fctStaDate?"old":""):"")+" href=javascript:; onclick='SelectDate(this)' title='"+varYear+"-"+(varMonth+1)+"-"+DayI+"'>"+DayI+"</a>";
	}

	return '<div class="DateListBox">'+varThisMonthHTML+'</div>';
}
//选择日期
function SelectDate(fctAObj){
	if(fctAObj.href||fctAObj.className=="aSelect"){
			var varValueObj=_G("divPyzyDateBox").Obj;
			var varValueToObj=GetValueToInputObj(varValueObj);
			if(varValueToObj)varValueObj=varValueToObj;
			//格式化日期格式 2009-2-2->2009-02-02 Modify By XiaoKang
			var thisDate=fctAObj.title;
			var thisArr=thisDate.split('-');
			var thisYear=thisArr[0];
			var thisMonth=thisArr[1];
			var thisDay=thisArr[2];
			thisMonth=parseInt(thisMonth)<10 ? thisMonth='0'+thisMonth:thisMonth;
			thisDay=parseInt(thisDay)<10 ? thisDay='0'+thisDay:thisDay;
			var thisResult=thisYear+'-'+thisMonth+'-'+thisDay;
			
			if(varValueObj.value==fctAObj.title){
				//varValueObj.value="";
			}else{
				varValueObj.value=thisResult;
			}
		_G("divPyzyDateBox").style.visibility="hidden";
		_G("divPyzyDateBox").bodyclick="";
		GetPyzyIframe("ifmdivPyzyDateBox","hidden");
		AutoNextInputAct(_G("divPyzyDateBox").Obj,"click");
	}
}
//隐藏日历
function HiddenDateBox(){
	if(_G("divPyzyDateBox")){
		if(_G("divPyzyDateBox").style.visibility!="hidden" && _G("divPyzyDateBox").bodyclick=="1"){
		_G("divPyzyDateBox").style.visibility="hidden";
		_G("divPyzyDateBox").bodyclick="";
			GetPyzyIframe("ifmdivPyzyDateBox","hidden");
		}else{
			_G("divPyzyDateBox").bodyclick="1";
		}
	}	
	
}
//显示日历
function ShowTwoMonthList(fctThisObj,fctJNum,fctStaDate){
	var varThisObjPosition=0;
	if(!fctJNum)fctJNum=0;
	if(!fctThisObj)fctThisObj="";
	var varStaDate=null,varTheDate=new Date();
	if(fctStaDate||fctStaDate==""){
		
		varStaDate=new Date(new Date()-86400000); //如果没有定义具体可使用的开始时间则自定义为今天
		var varStaDateSplit=fctStaDate.split("-");
		if(varStaDateSplit.length==3){
			varStaDate=new Date(varStaDateSplit[0],parseInt(varStaDateSplit[1],10)-1,varStaDateSplit[2]);//fctStaDate=new Date();
		}
		varTheDate=varStaDate;
		if(fctStaDate=="")fctStaDate=varStaDate.getFullYear()+"-"+(varStaDate.getMonth()+1)+"-"+varStaDate.getDate();
	}
	//alert(varStaDate);
	var varShowTwoMonthHTML="";
	for(var i=0+fctJNum;i<2+fctJNum;i++){
		varShowTwoMonthHTML+=GetMonthHTML((varStaDate?varStaDate:""),new Date(varTheDate.getFullYear(),varTheDate.getMonth()+i,1),i+1,fctJNum);
	}
	if(varStaDate)varShowTwoMonthHTML=varShowTwoMonthHTML.replace(/old href/g,"style=color:#999 old");
	if(fctThisObj.value!=""){ //对已选日期样式进行改变
		if(/^((\d{4})|(\d{2}))-(\d{1,2})-(\d{1,2})$/g.test(fctThisObj.value))varShowTwoMonthHTML=varShowTwoMonthHTML.replace(fctThisObj.value,fctThisObj.value+"' class='aSelect");
	}
	var varDateBoxObj = c_G("divPyzyDateBox","PyzyDateBox");
	varDateBoxObj.bodyclick="";
	if(fctThisObj!=""){ //调整坐标到合适位置
		varThisObjPosition=getPosition(fctThisObj);
		varDateBoxObj.style.top=(varThisObjPosition.top+varThisObjPosition.height)+"px";
		varDateBoxObj.style.left=(varThisObjPosition.left)+"px";
		varDateBoxObj.style.visibility="visible"; //hidden
		varDateBoxObj.Obj=fctThisObj;
	}
	
	//alert(varThisObjPosition.top+varThisObjPosition.height);
	//alert('<div style="margin-top:-1px;color:#B42929;font-size:12px;font-weight:bold;line-height:24px; position:absolute;margin-left:-290px;_margin-left:-305px;">&nbsp;<span style="padding-right:180px;_padding-right:240px;*padding-right:150px;cursor:pointer; font-weight:bold" onclick="ShowTwoMonthList(null,'+(fctJNum-1)+(fctStaDate?',\''+fctStaDate+'\'':'')+')" title="上月"><--</span><span style="cursor:pointer;" onclick="ShowTwoMonthList(null,'+(fctJNum+1)+(fctStaDate?',\''+fctStaDate+'\'':'')+')" title="下月">--></span></div>');
		//varDateBoxObj.innerHTML=varShowTwoMonthHTML+'<div style="margin-top:-1px;color:#B42929;font-size:12px;font-weight:bold;line-height:24px; position:absolute;margin-left:-290px;_margin-left:-305px;">&nbsp;<span style="padding-right:180px;_padding-right:240px;*padding-right:150px;cursor:pointer; font-weight:bold" onclick="ShowTwoMonthList(null,'+(fctJNum-1)+(fctStaDate?',\''+fctStaDate+'\'':'')+')" title="上月"><--</span><span style="cursor:pointer;" onclick="ShowTwoMonthList(null,'+(fctJNum+1)+(fctStaDate?',\''+fctStaDate+'\'':'')+')" title="下月">--></span></div>';
	//ShowTwoMonthList(null,(fctJNum-1)+(fctStaDate?',\''+fctStaDate+'\'':'')+')
	//alert((fctJNum-1)+(fctStaDate?',\''+fctStaDate+'\'':''))
	
GetPyzyIframe("ifmdivPyzyDateBox","visible",(varThisObjPosition.top+varThisObjPosition.height),varThisObjPosition.left,varDateBoxObj.offsetWidth,varDateBoxObj.offsetHeight); //取Iframe
varDateBoxObj.innerHTML=varShowTwoMonthHTML;
document.getElementsByTagName('body')[0].onclick=function(){HiddenDateBox();};
}
